#include "prs_rands.h"
#include <cstdio>
prs_rands::prs_rands()
{
	srand((uint32_t)time(NULL));//采用系统当前时钟作为种子
	n = 0;
	seq = NULL;
}

prs_rands::prs_rands(size_t _n)
{
	srand((uint32_t)time(NULL));//采用系统当前时钟作为种子
	n = _n;
	seq = new float_t[n];
	for (size_t i = 0; i < n; i++)
	{
		seq[i] = rand() / float_t(RAND_MAX);
	}
}

prs_rands::~prs_rands()
{
	if (seq != NULL)
	{
		delete seq;
	}
}

void prs_rands::set_seed(uint32_t _seed)
{
	srand(_seed);
}

void prs_rands::generate(size_t _n)
{
	/* 重新开辟存储空间 */
	if (_n != n)
	{
		n = _n;
		if (seq != NULL)
		{
			delete seq;
		}
		seq = new float_t[n];
	}
	/* 生成浮点随机序列 */
	for (size_t i = 0; i < n; i++)
	{
		seq[i] = float_t(rand());
	}
}


void prs_rands::bypass(size_t _n)
{
	/* 重新开辟存储空间 */
	if (_n != n)
	{
		n = _n;
		if (seq != NULL)
		{
			delete seq;
		}
		seq = new float_t[n];
	}
	/* 生成浮点随机序列 */
	for (size_t i = 0; i < n; i++)
	{
		seq[i] = rand() / float_t(RAND_MAX) + 1.0f;
	}
}
